home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / Multi-Panel Dialogs 1.1 / MPDTest App / Panels / CDefensePanel.cp < prev    next >
Encoding:
Text File  |  1996-02-09  |  4.9 KB  |  175 lines  |  [TEXT/R*ch]

  1. /*
  2.     File:            CDefensePanel.h
  3.  
  4.     Contains:    Class stub to use as a template for creating your own multi-pane
  5.                     dialog panels.
  6.  
  7.     Written by:    Mike Shields
  8.  
  9.     Copyright:    Copyright © 1996 Mike Shields.  All Rights Reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.                 02/01/96    MSS        New
  14.     To Do:
  15. */
  16. #include "CDefensePanel.h"
  17.  
  18. #include <LStream.h>
  19. #include <LControl.h>
  20.  
  21. struct SDefensePanelRec
  22. {
  23.     Int16        photons;
  24.     Int16        enableBoom;
  25.     Int16        boom;
  26.     Int16        shields;
  27. };
  28.  
  29. typedef struct SDefensePanelRec    DefensePanelDataRec, *DefensePanelDataPtr, **DefensePanelDataHandle;
  30.  
  31. //---------------------------------------------------------------------------
  32. // CDefensePanel::CreateFromStream
  33. //---------------------------------------------------------------------------
  34. CDefensePanel* CDefensePanel::CreateFromStream(LStream* inStream)
  35. {
  36.     return (new CDefensePanel(inStream));
  37. }
  38.  
  39. //---------------------------------------------------------------------------
  40. // CDefensePanel::CDefensePanel
  41. //---------------------------------------------------------------------------
  42. CDefensePanel::CDefensePanel()
  43. {
  44. }
  45.  
  46. //---------------------------------------------------------------------------
  47. // CDefensePanel::CDefensePanel
  48. //---------------------------------------------------------------------------
  49. CDefensePanel::CDefensePanel(const CDefensePanel &inOriginal) 
  50.     : CMPDPanel(inOriginal) 
  51. {
  52. }
  53.  
  54. //---------------------------------------------------------------------------
  55. // CDefensePanel::CDefensePanel
  56. //---------------------------------------------------------------------------
  57. CDefensePanel::CDefensePanel(const SPaneInfo &inPaneInfo, const SViewInfo &inViewInfo) 
  58.     : CMPDPanel(inPaneInfo, inViewInfo) 
  59. {
  60. }
  61.  
  62. //---------------------------------------------------------------------------
  63. // CDefensePanel::CDefensePanel
  64. //---------------------------------------------------------------------------
  65. CDefensePanel::CDefensePanel(LStream *inStream) 
  66.     : CMPDPanel(inStream)
  67. {
  68. }
  69.  
  70. //---------------------------------------------------------------------------
  71. // CDefensePanel::CDefensePanel
  72. //---------------------------------------------------------------------------
  73. CDefensePanel::~CDefensePanel()
  74. {
  75. }
  76.     
  77. //---------------------------------------------------------------------------
  78. // CDefensePanel::GetData
  79. //---------------------------------------------------------------------------
  80. void CDefensePanel::FinishCreateSelf()
  81. {
  82.     LControl        *aControl;
  83.     aControl = (LControl*)this->FindPaneByID('Eslf');
  84.     aControl->AddListener(this);
  85. }
  86.  
  87. //---------------------------------------------------------------------------
  88. // CDefensePanel::GetData
  89. //---------------------------------------------------------------------------
  90. void CDefensePanel::ListenToMessage(MessageT inMessage, void *ioParam)
  91. {
  92.     switch ( inMessage )
  93.     {
  94.         case 'Eslf':
  95.         {
  96.             LControl        *aControl;
  97.             aControl = (LControl*)this->FindPaneByID('Self');
  98.             if ( *(Int32*)ioParam == 1 )
  99.             {
  100.                 aControl->Enable();
  101.             }
  102.             else
  103.             {
  104.                 aControl->Disable();
  105.             }
  106.             break;
  107.         }
  108.     }
  109. }
  110.  
  111. //---------------------------------------------------------------------------
  112. // CDefensePanel::GetData
  113. //---------------------------------------------------------------------------
  114. void CDefensePanel::GetData(Handle inDataToReplace)
  115. {
  116.     LControl        *aControl;
  117.     DefensePanelDataRec    newPrefs;
  118.     
  119.     aControl = (LControl*)this->FindPaneByID('EPho');
  120.     newPrefs.photons = aControl->GetValue();
  121.     aControl = (LControl*)this->FindPaneByID('Eslf');
  122.     newPrefs.enableBoom = aControl->GetValue();
  123.     if ( newPrefs.enableBoom == 1 )
  124.     {
  125.         aControl = (LControl*)this->FindPaneByID('Self');
  126.         newPrefs.boom = aControl->GetValue();
  127.     }
  128.     else
  129.         newPrefs.boom = 0;
  130.     aControl = (LControl*)this->FindPaneByID('Off ');
  131.     if ( aControl->GetValue() == 1 )
  132.         newPrefs.shields = 1;    
  133.     else
  134.     {
  135.         aControl = (LControl*)this->FindPaneByID('On  ');
  136.         if ( aControl->GetValue() == 1 )
  137.             newPrefs.shields = 2;
  138.         else
  139.             newPrefs.shields = 3;
  140.     }
  141.     
  142.     OSErr anErr = ::PtrToXHand(&newPrefs, inDataToReplace, sizeof(newPrefs));
  143.     ThrowIfOSErr_(anErr);
  144. }
  145.  
  146. //---------------------------------------------------------------------------
  147. // CDefensePanel::SetData
  148. //---------------------------------------------------------------------------
  149. void CDefensePanel::SetData(Handle inData)
  150. {
  151.     LControl        *aControl;
  152.     DefensePanelDataHandle    newPrefs = (DefensePanelDataHandle)inData;
  153.     
  154.     aControl = (LControl*)this->FindPaneByID('EPho');
  155.     aControl->SetValue((**newPrefs).photons);
  156.     aControl = (LControl*)this->FindPaneByID('Eslf');
  157.     aControl->SetValue((**newPrefs).enableBoom);
  158.     aControl = (LControl*)this->FindPaneByID('Self');
  159.     if ( (**newPrefs).enableBoom == 1 )
  160.         aControl->SetValue((**newPrefs).boom);
  161.     else
  162.     {
  163.         aControl->Disable();
  164.         aControl->SetValue(0);
  165.     }
  166.  
  167.     aControl = (LControl*)this->FindPaneByID('Off ');
  168.     aControl->SetValue((**newPrefs).shields == 1 ? 1 : 0);
  169.     aControl = (LControl*)this->FindPaneByID('On  ');
  170.     aControl->SetValue((**newPrefs).shields == 2 ? 1 : 0);
  171.     aControl = (LControl*)this->FindPaneByID('High');
  172.     aControl->SetValue((**newPrefs).shields == 3 ? 1 : 0);
  173. }
  174.  
  175.